const state = {
  cartList: []
};

const mutations = {
  ADD_TO_CART(state, product) {
    const exist = state.cartList.find(item => item.id === product.id);
    if (exist) {
      exist.count += 1;
    } else {
      state.cartList.push({ ...product, count: 1 });
    }
  }
};

const getters = {
  cartCount: state => state.cartList.reduce((sum, item) => sum + item.count, 0)
};

export default {
  namespaced: true,
  state,
  mutations,
  getters
}; 